﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Universe.OneC.DomainModel;

namespace Universe.OneC
{
    public class MetaProcessorReader
    {
        private Adapter1C _adapter;

        public MetaProcessorReader(Adapter1C adapter)
        {
            _adapter = adapter;
        }

        public List<MetaProcessor> Get()
        {
            List<MetaProcessor> ret = new List<MetaProcessor>();
            object metadata = _adapter.GetMetadata();
            object processors = metadata.Get("Обработки");

            int count = (int) processors.Call("Count");
            for (int i = 0; i < count; i++)
            {
                object proc = processors.Call("Get", i);
                string name = (string) proc.Get("Name");
                string synonym = (string) proc.Get("Synonym");
                string comment = (string) proc.Get("Comment");
                proc.ReleaseComObject();

                ret.Add(
                    new MetaProcessor
                        {
                            Name = name,
                            Synonym = synonym,
                            Comments = comment
                        });
            }


            metadata.ReleaseComObject();
            processors.ReleaseComObject();


            return  ret;
        }
    }
}
